﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.Common;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;

namespace NetCoreCMS.Web.Areas.WebApi.Controllers
{
    public class User_Message_DeleteController : UserController
    {
        public IUser_messageService _user_message { get; set; }
        [Authorize]
        [HttpGet]
        public IActionResult Get(string check_id)
        {
            //检查用户是否登录
            Users model = GetUserInfo();
            if (model == null)
            {
                return Ok(new { status = 0, msg = "用户尚未登录或已超时!" });
            }
            if (string.IsNullOrEmpty(check_id))
            {
                return Ok(new { status = 0, msg = "删除失败，请检查传输参数！" });
            }
            string[] arrId = check_id.Split(',');
            for (int i = 0; i < arrId.Length; i++)
            {
                int id = Utils.StrToInt(arrId[i], 0);
                if (id > 0)
                {
                    _user_message.Delete(id, model.user_name);
                }
            }
            return Ok(new { status = 1, msg = "删除短消息成功！" });
        }
    }
}